<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.socket.io/4.4.1/socket.io.min.js"
        integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H"
        crossorigin="anonymous"></script>
</head>

<body>
    <input type="text" id="text">
    <input type="button" value="发送" onclick="send()">

    <script>
        var socket = io.connect('http://localhost:3000')
        socket.on('pushMsg', function (data) {
            console.log(data)
        })

        function send() {
            var text = document.getElementById('text').value;
            // message是自定义事件
            socket.emit('message', text);
        }
    </script>
</body>

</html>